﻿using System;
using UnityEngine;

namespace UnityModule
{
    public class SpawnPrefabInfo : IReference
    {
        public SpawnItemScheduler.RequestPriority Priority
        {
            get;
            set;
        } = SpawnItemScheduler.RequestPriority.Low;
        /// <summary>
        /// task
        /// </summary>
        private LoadTask m_LoadTask;

        public void SetLoadTask(LoadTask loadTask)
        {
            m_LoadTask = loadTask;
        }

        private Action<GameObject> CallBack;
        public void SetCallBack(Action<GameObject> callBack)
        {
            CallBack = callBack;
        }

        public void DoCallBack()
        {
            if(null != m_LoadTask && !m_LoadTask.IsDispose)
            {
                if (null == PoolWatcher){
                    CallBack?.Invoke(null);
                }
                else{
                    CallBack?.Invoke(PoolWatcher.Spawn());
                }
            }
        }

        private PrefabPool.PrefabPoolWatcher PoolWatcher;
        public void SetPoolWatcher(PrefabPool.PrefabPoolWatcher poolWatcher)
        {
            PoolWatcher = poolWatcher;
        }

        public SpawnPrefabInfo()
        {
        }

        public void Clear()
        {
            m_LoadTask = null;
            Priority = SpawnItemScheduler.RequestPriority.Low;
            PoolWatcher = null;
            CallBack = null;
        }
    }
}

